// components/message/index.js
import { useMessageStore } from '@/stores/message'

const Message = {
  // 显示 alert
  alert(options) {
    const messageStore = useMessageStore()
    messageStore.show('alert', options)
  },
  
  // 显示 confirm
  confirm(options) {
    const messageStore = useMessageStore()
    messageStore.show('confirm', options)
  },
  
  // 显示 loading
  loading(options) {
    const messageStore = useMessageStore()
    const defaultOptions = {
      title: '加载中...',
      text: '',
      color: '',
      width: 300,
      indeterminate: true,
      progressColor: 'primary'
    }
    messageStore.show('loading', { ...defaultOptions, ...options })
  },
  
  // 显示 prompt
  prompt(options) {
    const messageStore = useMessageStore()
    messageStore.show('prompt', options)
  },
  
  // 显示 toast
  toast(text, options = {}) {
    
    const messageStore = useMessageStore()
    // 确保传入的是字符串时正确处理
    const toastOptions = typeof text === 'string' 
      ? { text, ...options }
      : text
    messageStore.show('toast', toastOptions)
  },
  
  // 隐藏指定类型的消息
  hide(type) {
    const messageStore = useMessageStore()
    messageStore.hide(type)
  }
}

export default Message